package leetcode.code091;

public class Solution extends Solution091 {

	@Override
	public int numDecodings(String s) {
		int len = s.length();
		char[] chars = s.toCharArray();
		if (chars[0] == '0')
			return 0;
		int p1 = 1;// p2前一位可能数量
		int p2 = 1;// p3前一位可能数量
		int p3 = -1;// 达到当前位置，可能数量
		for (int i = 1; i < len; i++) {
			if (chars[i] == '0') {// 当前结尾时0
				if (chars[i - 1] > '2' || chars[i - 1] == '0')
					return 0;
				p3 = p1;
			} else if (chars[i - 1] == '1' && chars[i] >= '1' && chars[i] <= '9') {// 当前结尾1-9
				p3 = p2 + p1;
			} else if (chars[i - 1] == '2' && chars[i] >= '1' && chars[i] <= '6') {// 当前结尾1-6
				p3 = p2 + p1;
			} else {
				p3 = p2;
			}
			p1 = p2;
			p2 = p3;
		}
		return p2;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();
//		for (int i = 0; i < 10; i++) {
//			System.out.println((i + "").charAt(0));
//		}
		System.out.println(0 % 3);
	}

}
